﻿//////////////////////////////////////////////////////////////////////////
// FileName:fmCarMaintenanceForm.aspx
// CreateBy:DragonXiong
// CreateDate:2010-05-22
// Description:
//		Car Maintenance Form
//      
// Modify Log:
//	
// Copyright:
/////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Auto.Web.Common;
using Auto.Components;
using Model = Auto.Data.BusMan.Model;
using BLL = Auto.Data.BusMan.BLL;

namespace Auto.BusMan
{
    public partial class fmBuyOilAdd : System.Web.UI.Page
    {
        public string DocID
        {
            get
            {
                ViewState["DocID"] = Request.QueryString["DocID"];
                return (ViewState["DocID"] == null) ? "" : ViewState["DocID"].ToString();
            }
            set { ViewState["DocID"] = value; }
        }

        Model.BuyOilManage model = new Model.BuyOilManage();
        BLL.BuyOilManage bll = new BLL.BuyOilManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            if (string.IsNullOrEmpty(DocID)) //新增
            {
                this.chkAddContinue.Checked = true;
                checktr.Visible = true;
                checktr.Attributes.Add("style", "display:block;");
                InitControl();
            }
            else  //修改
            {

                checktr.Attributes.Add("style", "display:none;");
                BindData();
            }
        }

        private void ClearText()
        {
            this.txtBuyDate.Text = "";
            this.txtCost.Text = "";
        }

        private void InitControl()
        {


        }

        private Model.BuyOilManage GetBuyOilManage()
        {
            if (!string.IsNullOrEmpty(DocID))
            {
                model = (Model.BuyOilManage)Session["fmBuyOilAdd.Model"];
            }
            //Tab1
            DateTime BuyDate = DateTime.Parse(this.txtBuyDate.Text);
            //string Buyer = this.txtBuyer.Text;
            decimal Cost = decimal.Parse(this.txtCost.Text);
            //string Note = this.txtNote.Text;

            //Tab1
            model.BuyDate = BuyDate;
            //model.Buyer = Buyer;
            model.Cost = Cost;
            //model.Note = Note;
            return model;
        }

        #region --BindData--
        protected void BindData()
        {
            InitControl();
            model = bll.GetModel(DocID);
            Session["fmBuyOilAdd.Model"] = model;
            txtBuyDate.CalendarDate = model.BuyDate;
            txtCost.Text = model.Cost.ToString();
        }

        #endregion --BindData--


        private bool Check()
        {
            string strErr = "";

            if (txtBuyDate.Text == "")
            {
                strErr += "请选择时间!\\n";
            }

            if (strErr != "")
            {
                Jscript.AjaxAlert(this, strErr);
                return false;
            }
            else
            {
                return true;
            }
        }

        #region Event

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Check())
            {
                return;
            }
            try
            {
                model = GetBuyOilManage();
                model.RecDivID = SessionBox.User.DivID;
                model.UserAcct = SessionBox.User.UserID;
                if (string.IsNullOrEmpty(DocID))
                {
                    bll.Add(model);
                }
                else
                {
                    bll.Update(model);
                }
                Redirect();

            }
            catch (Exception ex)
            {
                Jscript.AjaxAlert(this, ex.Message);
            }

        }
        private void Redirect()
        {
            if (chkAddContinue.Checked)
            {
                lblMsg.Text = "保存成功，请继续添加！";
                ClearText();
            }
            else
            {
                Server.Transfer("fmBuyOilList.aspx");
            }
        }
        #endregion Event
    }
}